<template>
	<el-dialog title="添加权限信息" :visible.sync="dialogVisible" width="650px" @close="handleClose"
		:close-on-click-modal="false">
		<div slot="title" class="dialog-header-title">
			<i class="el-icon-edit-outline"></i>
			<span>添加权限信息</span>
		</div>

		<div class="smp-search" v-if="dialogVisible">
			<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">

				<el-row>
					<el-col :span="24">
						<el-col :span="24">
							<el-form-item label="权限编号:" prop="permissionId">
								<el-input v-model="form.permissionId" placeholder="权限编号"></el-input>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="权限名称:" prop="permissionName">
								<el-input v-model="form.permissionName" placeholder="权限名称"></el-input>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="权限类型:" prop="permissionType">
								<el-select v-model="form.permissionType" style="width: 100%" placeholder="权限类型">
									<el-option v-for="item in dict('SMP0021')" :key="item.itemCode" :label="item.itemName" :value="item.itemCode"></el-option>
								</el-select>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="权限状态:" prop="permissionStatus">
								<el-select v-model="form.permissionStatus" style="width: 100%" placeholder="权限状态">
									<el-option v-for="item in dict('SMP0005')" :key="item.itemCode" :label="item.itemName" :value="item.itemCode"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="权限描述:" prop="permissionDescription">
								<el-input type="textarea" v-model="form.permissionDescription" placeholder="权限描述"></el-input>
							</el-form-item>
						</el-col>

						
					</el-col>
				</el-row>


			</el-form>
		</div>
		<span slot="footer" class="dialog-footer">
			<!-- <el-button size="mini" type="primary" @click="onSubmit">确定</el-button>
			<el-button size="mini" @click="closeDialog">取消</el-button> -->
			
			<el-button type="primary" plain @click="onSubmit" size="mini">
				<i class="el-icon-check"></i>
				确定</el-button>
			<el-button @click="closeDialog" size="mini">
				<i class="el-icon-close"></i>
				取消</el-button>
		</span>
	</el-dialog>
</template>

<script>
	"use strict";
	import {
		addPermissionInfo
	} from '@/api/permission.js';

	export default {


		data() {
			return {
				dialogVisible: false,
				rules: {
					permissionId: [{
						required: true,
						message: "权限编号不能为空",
						trigger: ['blur', 'change']
					}],
					permissionName: [{
						required: true,
						message: "权限名称不能为空",
						trigger: ['blur', 'change']
					}],
					permissionType: [{
						required: true,
						message: "权限类型不能为空",
						trigger: ['blur', 'change']
					}],
					permissionStatus: [{
						required: true,
						message: "权限状态不能为空",
						trigger: ['blur', 'change']
					}]
				},
				form: {
					permissionId: '',
					permissionName: '',
					permissionType: '',
					permissionStatus: '',
					permissionDescription: ''
				},

			};
		},


		methods: {

			onSubmit() {
				this.addPermissionInfo();
			},


			addPermissionInfo() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						addPermissionInfo(this.form).then(response => {
							
							this.$message({
						duration:5000,
								type: 'success',
								message: '权限信息添加成功！'
							});
							this.form = {};
							this.dialogVisible = false;
							this.$emit("onSubmit");


						}).catch(error => {
							this.$message({
						duration:5000,								type: 'error',
								message: '权限信息添加失败！'
							});
							this.form = {};
							this.dialogVisible = false;
						});
					}
				})

			},

			showDialog() {
				this.dialogVisible = true;
			},

			closeDialog() {
				this.form = {};
				this.dialogVisible = false;
			},

			handleClose() {
				this.form = {};
				this.dialogVisible = false;
			}


		},

	}
</script>

<style>
</style>
